function useMouse() {
  const x = ref(0)
  const y = ref(0)
  window.addEventListener('mousemove', handler)
  function handler(e) {
    x.value = e.x
    y.value = e.y
  }
  onScopeDispose(() => {
    window.removeEventListener('mousemove', handler)
  })
  return {x,y}
}

function createSharedComposable(composable) {
  let subscribers = 0
  let state, scope
  const dispose = () => {
    if (scope && --subscribers <= 0) {
      scope.stop()
      state = scope = null
    }
  }
  // 这里只有在第一次运行的时候创建一个state, 后面所有的组件就不会再创建新的state，而是共用一个state
  return (...args) => {
    subscribers++
    if (!state) {
      scope = effectScope(true)
      state = scope.run(() => composable(...args))
    }
    onScopeDispose(dispose)
    return state
  }
} 
const useSharedMouse = createSharedComposable(useMouse)

useSharedMouse().x